<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/pages/template.xhtml">
<body>
<ui:define name="content">
<f:view>
	<h:form>
	
		<h:messages/>
		 <fieldset>
	        <legend>Pesquisa de Pessoas</legend>
			<h:panelGrid columns="2">
			
			    <h:outputLabel for="nomeLabel" value="Digite o nome: " />
				<h:inputText id="nomeInput" value="#{pessoaMB.pessoa.nome}" style=" width : 321px;" />

				<h:commandButton value="Pesquisar" action="#{pessoaMB.pesquisaByNome}" styleClass="botoes"/>
				<h:commandButton value="Voltar" immediate="true" action="#{pessoaMB.voltar}" styleClass="botoes"/>
    		</h:panelGrid>
			
		   
		     
			<rich:dataTable  id="fisicas" value="#{pessoaMB.listPessoas}" var="testando"  rowKeyVar="row" rows="4"  rendered="#{not empty pessoaMB.listPessoas}" reRender="ds">
				      <rich:column sortBy="#{testando.nome}">
				         <f:facet name="header">Name</f:facet>
					    <h:outputText id="nomePessoa" value="#{testando.nome}" />
					 </rich:column>
	 
				      <rich:column sortBy="#{testando.email}">
				         <f:facet name="header">Email</f:facet>
				         <h:outputText id="emailPessoa" value="#{testando.email}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{testando.cpf}">
				         <f:facet name="header">Cpf</f:facet>
				         <h:outputText id="cpfPessoa" value="#{testando.cpf}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{testando.dataNascimento}">
				         <f:facet name="header">Data Nascimento</f:facet>
				         <h:outputText id="nascimento" value="#{testando.dataNascimento}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{testando.telefoneCelular}">
				         <f:facet name="header">Telefone</f:facet>
				         <h:outputText id="telPessoa"   value="#{testando.telefoneCelular}">
				         	<f:convertDateTime pattern="dd/MM/yyyy"/>  
				         </h:outputText>
				         
				      </rich:column>
				      
				      <rich:column >
				      		<f:facet name="header"> Editar </f:facet>
							<a4j:commandLink   id="show" ajaxSingle="true" reRender="panelGridInputs"  oncomplete="#{rich:component('editPanel')}.show()">
							<h:graphicImage value="/images/edit.gif"/>
							<f:setPropertyActionListener  value="#{testando}" target="#{pessoaMB.linha}"/>
							</a4j:commandLink >
							<rich:toolTip for="show" value="Editar" />
					</rich:column>
				      <rich:column >
				      		<f:facet name="header"> Excluir </f:facet>
							<a4j:commandLink  ajaxSingle="true" id="deleta" 
							oncomplete="#{rich:component('deletePanel')}.show()"
							status="sts">
							<h:graphicImage value="/images/delete.png"/>
							<f:setPropertyActionListener  value="#{row}" target="#{pessoaMB.row}"/>
							<f:setPropertyActionListener  value="#{testando}" target="#{pessoaMB.linha}"/>
							</a4j:commandLink >
							 <rich:toolTip for="deleta" value="Delete" />
					</rich:column>
		               <f:facet name="footer">
		                <rich:datascroller id="ds"></rich:datascroller>
		              </f:facet>
</rich:dataTable>


			 <a4j:region id="regiaoAjax">
			 	<a4j:status id="sts">
	            	<f:facet name="start">
	            		<h:graphicImage value="/images/ajax-loader.gif" />
	               	</f:facet>
	            </a4j:status>
	         </a4j:region>
	    </fieldset>
	</h:form>
	<a4j:keepAlive beanName="pessoaMB"/>
	
	    <rich:modalPanel id="deletePanel" autosized="true" width="200">
        <f:facet name="header">
            <h:outputText value="Quer deletar essa linha?"
                style="padding-right:15px;" />
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage value="/images/delete.png"
                    styleClass="hidelink" id="hidelink2" />
                <rich:componentControl for="deletePanel" attachTo="hidelink2"
                    operation="hide" event="onclick" />
            </h:panelGroup>
        </f:facet>
        <h:form>
            <table width="100%">
                <tbody>
                    <tr>
                        <td align="center" width="50%">
	                        	<a4j:commandButton value="Yes"
	                        	ajaxSingle="true"
	                            action="#{pessoaMB.delete}"
	                            reRender="fisicas" oncomplete="#{rich:component('deletePanel')}.hide();" />
                            </td>
                        <td align="center" width="50%">
                        	<a4j:commandButton
                            value="Cancel"
                            onclick="Richfaces.hideModalPanel('deletePanel');"/>
                        </td>
                    </tr>
                </tbody>
            </table>
        </h:form>
    </rich:modalPanel>
    
	<rich:modalPanel id="editPanel" autosized="true" width="450" >
	
        <f:facet name="header">
            <h:outputText value="Edit..." />
        </f:facet>
        <h:form>
            <rich:messages style="color:red;"></rich:messages>
			<h:panelGrid columns="2" id="panelGridInputs">
			
			
				<h:outputLabel for="nome" value="Nome "  />
				<h:inputText id="nome" value="#{pessoaMB.linha.nome}" style=" width : 254px;"/>
				
				<h:outputLabel for="email" value="E-mail "  />
				<h:inputText id="email" value="#{pessoaMB.linha.email}" style=" width : 249px;">
					<f:validator validatorId="emailValidator"/>
				</h:inputText>
				
				<h:outputLabel for="cpf" value="CPF "  />
				<h:inputText id="cpf" validatorMessage="CPF inválido!" value="#{pessoaMB.linha.cpf}" size="60" style=" width : 106px;">
					
				</h:inputText>
				
				<h:outputLabel for="dataNasc" value="Data Nascimento: "  />
				<h:inputText id="dataNasc" validatorMessage="Data de nascimento com formato inválido!" value="#{pessoaMB.linha.dataNascimento}" size="60" style=" width : 75px;">
					<f:convertDateTime pattern="dd/MM/yyyy" />
					
				</h:inputText> 
					
				<h:outputLabel for="telCel" value="Tel. Celular "  />
				<h:inputText id="telCel" value="#{pessoaMB.linha.telefoneCelular}">
					
				</h:inputText>
				
				<a4j:commandButton value="Atualizar" action="#{pessoaMB.update}"  oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editPanel')}.hide();" styleClass="botoes" status="sts"  reRender="nomePessoa, emailPessoa, cpfPessoa, telPessoa"/>
				<a4j:commandButton value="Voltar"  onclick="Richfaces.hideModalPanel('editPanel');" 
				/>
				
			</h:panelGrid>

			</h:form>
    </rich:modalPanel>
</f:view>
</ui:define>
</body>
</ui:composition >
